﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Threading.Tasks;

namespace RBACProject.Repositories
{
                                                                    //  new()  泛型约束 允许实例化
    public interface IBaseRepository<TEntity> where TEntity : class, new()
    {

        /// <summary>
        /// 添加
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        TEntity Insert(TEntity entity);

        /// <summary>
        /// 添加  (异步)
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        Task<TEntity> InsertAsync(TEntity entity);

        /// <summary>
        /// 批量添加 (异步)
        /// </summary>
        /// <param name="entities"></param>
        /// <returns></returns>
        Task<int> InsertManyAsync(List<TEntity> entities);

        /// <summary>
        /// 单个删除  按主键Id)  (异步)
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        Task<int> DeleteAsyncById(int id);

        /// <summary>
        ///  删除   按照条件 (异步)
        /// </summary>
        /// <param name="predicate"></param>
        /// <returns></returns>  
        Task<int> DeleteAsyncWhere(Expression<Func<TEntity, bool>> predicate);

        /// <summary>
        /// 批量删除    (异步)
        /// </summary>
        /// <param name="entities"></param>
        /// <returns></returns>
        Task<int> BathDeleteAsync(List<TEntity> entities);


        /// <summary>
        ///  更新 修改 (异步)
        /// </summary>
        /// <param name="predicate"></param>
        /// <returns></returns>
        Task<TEntity> UpdateAsnyc(TEntity entity);



        /// <summary>
        /// 查询  全部
        /// </summary>
        /// <returns></returns>
        IQueryable<TEntity> QueryAsnycAll();

        /// <summary>
        /// 查询   按主键
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        Task<TEntity> QueryAsnycById(int id);

        /// <summary>
        /// 查询    查询实体
        /// </summary>
        /// <param name="predicate"></param>
        /// <returns></returns>
        Task<TEntity> QueryAsnycEntity(Expression<Func<TEntity, bool>> predicate);

        /// <summary>
        /// 查询   按条件   （异步）
        /// </summary>
        /// <param name="predicate"></param>
        /// <returns></returns>
        Task<List<TEntity>> QueryWhere(Expression<Func<TEntity, bool>> predicate);
  

        /// <summary>
        /// 查询    是否存在 
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        Task<bool> ExistsAsnyc(Expression<Func<TEntity, bool>> predicate);







    }
}